package com.tshopping.dao;

import com.tshopping.bean.Store;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;

@Repository
public interface StoreDao {
    @Insert("insert into store (user,address,name,description,picture) values (#{user},#{address},#{name},#{description},#{picture})")
    boolean addStore(@Param("user") int user, @Param("address") String address, @Param("name") String name, @Param("description") String description, @Param("picture") String picture);

    @Select("select * from store where user = #{user} and isApprove=1")
    Store selectStoreByUserId(@Param("user") int user);

    @Update("update store set address=#{address},name=#{name},description=#{description},picture=#{picture},isApprove=#{isApprove} where user=#{user} and id=#{id}")
    boolean updateStoreByUserIdAndStoreId(@Param("address") String address, @Param("name") String name, @Param("description") String description, @Param("picture") String picture, @Param("isApprove") int isApprove, @Param("user") int user, @Param("id") int id);

    @Delete("delete form store where user=#{user} and id=#{id}")
    boolean deleteStoreByUserIdAndStoreId(@Param("user") int user, @Param("id") int id);

    @Select("select * from store where id=#{id}")
    Store selectStoreByStoreId(@Param("id") int id);

    @Update("update store set saleRoom=saleRoom+#{saleRoom},salesVolume=salesVolume+#{salesVolume} where id=#{id}")
    boolean addStoreSaleRoomAndSalesVolume(@Param("saleRoom") int saleRoom, @Param("salesVolume") double salesVolume, @Param("id") int id);

    @Update("update store set saleRoom=saleRoom-#{saleRoom},salesVolume=salesVolume-#{salesVolume} where id=#{id}")
    boolean backStoreSaleRoomAndSalesVolume(@Param("saleRoom") int saleRoom, @Param("salesVolume") double salesVolume, @Param("id") int id);

    @Select("select count(*) from store")
    int selectStoreCount();

    @Select("select * from store limit #{start},#{size}")
    ArrayList<Store> selectAllStore(@Param("start")int start,@Param("size") int size);

    @Delete("delete from store where id=#{id}")
    boolean deleteStore(@Param("id") int id);

    @Update("update store set isApprove=#{isApprove} where id=#{id}")
    boolean updateStoreApprove(@Param("isApprove")int isApprove,@Param("id")int id);

    @Select("select user from store where id=#{id}")
    int selectUserByStoreId(@Param("id")int id);

}
